#include<QDir>
#include<QFile> 

#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[]){
	QDir testdir("src");
	testdir.setNameFilters(QStringList("*.cpp"));
	for(uint i = 0; i < testdir.count(); i++){
		QString testname = testdir[i].remove(".cpp");
		QString testProName = testname + ".pro";
		QString testMakefile = "Makefile_" + testname;
		QString filepath = testdir.absoluteFilePath(testdir[i]);
		printf("%s, %s\n", testname.toUtf8().data(), filepath.toUtf8().data());
		
		QString catString = "cat ../build/build.pro > " + testProName;
		
		if(system(catString.toUtf8().data())){
			printf("Something went wrong in QProcess::execute()\n");
			continue;
		}
		
		system( ("echo \"QT += testlib\" >> " + testProName).toUtf8().data() );
		system( ("echo \"SOURCES -= ../src/Main.cpp\" >> " + testProName).toUtf8().data() );
		system( ("echo \"SOURCES += " + filepath + "\" >> " + testProName).toUtf8().data() );
		system( ("qmake " + testProName + " -o " + testMakefile).toUtf8().data() );
	}
	return 0;
}
